<template>
<div class="topnav">
    <router-link to='/' class="logo">
        <svg class="icon" aria-hidden="true">
            <use xlink:href="#icon-paoxie"></use>
        </svg>
    </router-link>
    <ul class="menu">
        <li>
            <router-link to="/doc">文档</router-link>
        </li>
    </ul>
    <svg v-if="toggleMenuButtonVisible" class="toggleAside" @click="toggleMenu">
        <use xlink:href="#icon-menu"></use>
    </svg>
</div>
</template>

<style lang="scss" scoped>
.topnav {
    left: 0;
    top: 0;
    width: 100%;
    display: flex;
    padding: 16px;
    position: fixed;
    justify-content: center;
    align-items: center;
    z-index: 20;

    >.logo {
        max-width: 6em;
        //margin-right: auto影响上面flex布局的居中设置
        margin-right: auto;

        >svg {
            width: 32px;
            height: 32px;
        }
    }

    >.menu {
        display: flex;
        white-space: nowrap;
        flex-wrap: nowrap;

        >li {
            font-size: 20px;
            margin: 0 1em;
            list-style: none;

            &:hover {
                color: #ff008a;
                text-decoration: none;
            }
        }
    }

    >.toggleAside {
        display: none;
        width: 24px;
        height: 24px;
        position: absolute;
        left: 16px;
        top: 50%;
        transform: translateY(-50%);

    }

    //最大宽度为500px，若是在此条件范围下，则执行以下样式
    @media (max-width:500px) {
        >.menu {
            display: none;
        }

        //margin:0 auto指示着与上下外边距为0，左右属于自动调节，覆盖掉margin-right: auto的设置
        >.logo {
            margin: 0 auto;
        }

        >.toggleAside {
            display: inline-block;
        }
    }
}
</style>

<script lang="ts">
import {
    Ref,
    inject
} from 'vue';
export default {
    props: {
        toggleMenuButtonVisible: {
            type: Boolean,
            default: false,
        }
    },
    setup() {
        const asideVisible = inject < Ref < Boolean >> ('nav');
        //输出的要是asideVisible的值
        //console.log("Nav获取到app.vue的显示变量为" + asideVisible.value);
        const toggleMenu = () => {
            //触发的修改，作非运算
            asideVisible.value = !asideVisible.value;
        }
        return {
            toggleMenu
        };
    }
}
</script>
